<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>高级处理-数据离散化 | 机器学习（常用科学计算库的使用）基础定位、目标</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-katex/katex.min.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../Pandas/section9.html" />
    
    
    <link rel="prev" href="../Pandas/section7.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.8"
        data-chapter-title="高级处理-数据离散化"
        data-filepath="Pandas/section8.md"
        data-basepath=".."
        data-revision="Sat Jul 20 2019 23:53:14 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        机器学习（常用科学计算库的使用）基础定位、目标
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="ml_pre/index.html">
            
                
                    <a href="../ml_pre/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        机器学习概述
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="ml_pre/section1.html">
            
                
                    <a href="../ml_pre/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        人工智能概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="ml_pre/section2.html">
            
                
                    <a href="../ml_pre/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        人工智能发展历程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="ml_pre/section3.html">
            
                
                    <a href="../ml_pre/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        人工智能主要分支
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="ml_pre/section4.html">
            
                
                    <a href="../ml_pre/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        机器学习工作流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ml_pre/section5.html">
            
                
                    <a href="../ml_pre/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        机器学习算法分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="ml_pre/section6.html">
            
                
                    <a href="../ml_pre/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        模型评估
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="ml_pre/section7.html">
            
                
                    <a href="../ml_pre/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        Azure机器学习模型搭建实验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ml_pre/section8.html">
            
                
                    <a href="../ml_pre/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        深度学习简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="env/index.html">
            
                
                    <a href="../env/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        机器学习基础环境安装与使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="env/section1.html">
            
                
                    <a href="../env/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="env/section2.html">
            
                
                    <a href="../env/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        jupyter notebook使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="Matplotlib/index.html">
            
                
                    <a href="../Matplotlib/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Matplotlib
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="Matplotlib/section1.html">
            
                
                    <a href="../Matplotlib/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Matplotlib之HelloWorld
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="Matplotlib/section2.html">
            
                
                    <a href="../Matplotlib/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        基础绘图功能 — 以折线图为例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="Matplotlib/section3.html">
            
                
                    <a href="../Matplotlib/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        常见图形绘制
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Numpy/index.html">
            
                
                    <a href="../Numpy/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Numpy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Numpy/section1.html">
            
                
                    <a href="../Numpy/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Numpy的优势
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="Numpy/section2.html">
            
                
                    <a href="../Numpy/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        N维数组-ndarray
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="Numpy/section3.html">
            
                
                    <a href="../Numpy/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        基本操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="Numpy/section4.html">
            
                
                    <a href="../Numpy/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        ndarray运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="Numpy/section5.html">
            
                
                    <a href="../Numpy/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        数组间的运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="Numpy/section6.html">
            
                
                    <a href="../Numpy/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        数学：矩阵
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="Pandas/index.html">
            
                
                    <a href="../Pandas/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="Pandas/section1.html">
            
                
                    <a href="../Pandas/section1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Pandas介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="Pandas/section2.html">
            
                
                    <a href="../Pandas/section2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        Pandas数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="Pandas/section3.html">
            
                
                    <a href="../Pandas/section3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        基本数据操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="Pandas/section4.html">
            
                
                    <a href="../Pandas/section4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        DataFrame运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="Pandas/section5.html">
            
                
                    <a href="../Pandas/section5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        Pandas画图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="Pandas/section6.html">
            
                
                    <a href="../Pandas/section6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        文件读取与存储
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="Pandas/section7.html">
            
                
                    <a href="../Pandas/section7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        高级处理-缺失值处理
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.8" data-path="Pandas/section8.html">
            
                
                    <a href="../Pandas/section8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        高级处理-数据离散化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="Pandas/section9.html">
            
                
                    <a href="../Pandas/section9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        高级处理-合并
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="Pandas/section10.html">
            
                
                    <a href="../Pandas/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        高级处理-交叉表与透视表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.11" data-path="Pandas/section11.html">
            
                
                    <a href="../Pandas/section11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        高级处理-分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="Pandas/section12.html">
            
                
                    <a href="../Pandas/section12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="ReadingExtension/index.html">
            
                
                    <a href="../ReadingExtension/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        拓展知识
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="ReadingExtension/1.完整机器学习项目的流程.html">
            
                
                    <a href="../ReadingExtension/1.完整机器学习项目的流程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        完整机器学习项目的流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="ReadingExtension/2.独立同分布.html">
            
                
                    <a href="../ReadingExtension/2.独立同分布.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        独立同分布
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >机器学习（常用科学计算库的使用）基础定位、目标</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="58-&#x9AD8;&#x7EA7;&#x5904;&#x7406;&#x6570;&#x636E;&#x79BB;&#x6563;&#x5316;">5.8 &#x9AD8;&#x7EA7;&#x5904;&#x7406;-&#x6570;&#x636E;&#x79BB;&#x6563;&#x5316;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x76EE;&#x6807; <ul>
<li>&#x5E94;&#x7528;cut&#x3001;qcut&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x7684;&#x533A;&#x95F4;&#x5206;&#x7EC4;</li>
<li>&#x5E94;&#x7528;get_dummies&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x7684;one-hot&#x7F16;&#x7801;</li>
</ul>
</li>
</ul>
<hr>
<h2 id="1--&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x79BB;&#x6563;&#x5316;">1  &#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x79BB;&#x6563;&#x5316;</h2>
<p>&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x79BB;&#x6563;&#x5316;&#x7684;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x7B80;&#x5316;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;<strong>&#x6570;&#x636E;&#x79BB;&#x6563;&#x5316;&#x6280;&#x672F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x51CF;&#x5C11;&#x7ED9;&#x5B9A;&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x4E2A;&#x6570;</strong>&#x3002;&#x79BB;&#x6563;&#x5316;&#x65B9;&#x6CD5;&#x7ECF;&#x5E38;&#x4F5C;&#x4E3A;&#x6570;&#x636E;&#x6316;&#x6398;&#x7684;&#x5DE5;&#x5177;&#x3002;</p>
<h2 id="2-&#x4EC0;&#x4E48;&#x662F;&#x6570;&#x636E;&#x7684;&#x79BB;&#x6563;&#x5316;">2 &#x4EC0;&#x4E48;&#x662F;&#x6570;&#x636E;&#x7684;&#x79BB;&#x6563;&#x5316;</h2>
<p><strong>&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x7684;&#x79BB;&#x6563;&#x5316;&#x5C31;&#x662F;&#x5728;&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x57DF;&#x4E0A;&#xFF0C;&#x5C06;&#x503C;&#x57DF;&#x5212;&#x5206;&#x4E3A;&#x82E5;&#x5E72;&#x4E2A;&#x79BB;&#x6563;&#x7684;&#x533A;&#x95F4;&#xFF0C;&#x6700;&#x540E;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x7B26;&#x53F7;&#x6216;&#x6574;&#x6570;</strong>
<strong>&#x503C;&#x4EE3;&#x8868;&#x843D;&#x5728;&#x6BCF;&#x4E2A;&#x5B50;&#x533A;&#x95F4;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x3002;</strong></p>
<p>&#x79BB;&#x6563;&#x5316;&#x6709;&#x5F88;&#x591A;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4F7F;&#x7528;&#x4E00;&#x79CD;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F;&#x53BB;&#x64CD;&#x4F5C;</p>
<ul>
<li>&#x539F;&#x59CB;&#x4EBA;&#x7684;&#x8EAB;&#x9AD8;&#x6570;&#x636E;&#xFF1A;165&#xFF0C;174&#xFF0C;160&#xFF0C;180&#xFF0C;159&#xFF0C;163&#xFF0C;192&#xFF0C;184</li>
<li>&#x5047;&#x8BBE;&#x6309;&#x7167;&#x8EAB;&#x9AD8;&#x5206;&#x51E0;&#x4E2A;&#x533A;&#x95F4;&#x6BB5;&#xFF1A;150~165, 165~180,180~195</li>
</ul>
<p>&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x5C06;&#x6570;&#x636E;&#x5206;&#x5230;&#x4E86;&#x4E09;&#x4E2A;&#x533A;&#x95F4;&#x6BB5;&#xFF0C;&#x6211;&#x53EF;&#x4EE5;&#x5BF9;&#x5E94;&#x7684;&#x6807;&#x8BB0;&#x4E3A;&#x77EE;&#x3001;&#x4E2D;&#x3001;&#x9AD8;&#x4E09;&#x4E2A;&#x7C7B;&#x522B;&#xFF0C;&#x6700;&#x7EC8;&#x8981;&#x5904;&#x7406;&#x6210;&#x4E00;&#x4E2A;&quot;&#x54D1;&#x53D8;&#x91CF;&quot;&#x77E9;&#x9635;</p>
<h2 id="3-&#x80A1;&#x7968;&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x79BB;&#x6563;&#x5316;">3 &#x80A1;&#x7968;&#x7684;&#x6DA8;&#x8DCC;&#x5E45;&#x79BB;&#x6563;&#x5316;</h2>
<p>&#x6211;&#x4EEC;&#x5BF9;&#x80A1;&#x7968;&#x6BCF;&#x65E5;&#x7684;&quot;p_change&quot;&#x8FDB;&#x884C;&#x79BB;&#x6563;&#x5316;</p>
<p><img src="images/&#x54D1;&#x53D8;&#x91CF;&#x77E9;&#x9635;.png" alt="&#x54D1;&#x53D8;&#x91CF;&#x77E9;&#x9635;"></p>
<h3 id="31-&#x8BFB;&#x53D6;&#x80A1;&#x7968;&#x7684;&#x6570;&#x636E;">3.1 &#x8BFB;&#x53D6;&#x80A1;&#x7968;&#x7684;&#x6570;&#x636E;</h3>
<p>&#x5148;&#x8BFB;&#x53D6;&#x80A1;&#x7968;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x7B5B;&#x9009;&#x51FA;p_change&#x6570;&#x636E;</p>
<pre><code class="lang-python">data = pd.read_csv(<span class="hljs-string">&quot;./data/stock_day.csv&quot;</span>)
p_change= data[<span class="hljs-string">&apos;p_change&apos;</span>]
</code></pre>
<h3 id="32-&#x5C06;&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5206;&#x7EC4;">3.2 &#x5C06;&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5206;&#x7EC4;</h3>
<p><img src="images/&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x5206;&#x7EC4;.png" alt="&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x5206;&#x7EC4;"></p>
<p>&#x4F7F;&#x7528;&#x7684;&#x5DE5;&#x5177;&#xFF1A;</p>
<ul>
<li>pd.qcut(data, q)&#xFF1A;<ul>
<li>&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5206;&#x7EC4;&#x5C06;&#x6570;&#x636E;&#x5206;&#x7EC4;&#xFF0C;&#x4E00;&#x822C;&#x4F1A;&#x4E0E;value_counts&#x642D;&#x914D;&#x4F7F;&#x7528;&#xFF0C;&#x7EDF;&#x8BA1;&#x6BCF;&#x7EC4;&#x7684;&#x4E2A;&#x6570;</li>
</ul>
</li>
<li>series.value_counts()&#xFF1A;&#x7EDF;&#x8BA1;&#x5206;&#x7EC4;&#x6B21;&#x6570;</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x81EA;&#x884C;&#x5206;&#x7EC4;</span>
qcut = pd.qcut(p_change, <span class="hljs-number">10</span>)
<span class="hljs-comment"># &#x8BA1;&#x7B97;&#x5206;&#x5230;&#x6BCF;&#x4E2A;&#x7EC4;&#x6570;&#x636E;&#x4E2A;&#x6570;</span>
qcut.value_counts()
</code></pre>
<p>&#x81EA;&#x5B9A;&#x4E49;&#x533A;&#x95F4;&#x5206;&#x7EC4;&#xFF1A;</p>
<ul>
<li>pd.cut(data, bins)</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x81EA;&#x5DF1;&#x6307;&#x5B9A;&#x5206;&#x7EC4;&#x533A;&#x95F4;</span>
bins = [-<span class="hljs-number">100</span>, -<span class="hljs-number">7</span>, -<span class="hljs-number">5</span>, -<span class="hljs-number">3</span>, <span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">7</span>, <span class="hljs-number">100</span>]
p_counts = pd.cut(p_change, bins)
</code></pre>
<h3 id="33-&#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x5206;&#x7EC4;&#x6570;&#x636E;&#x53D8;&#x6210;onehot&#x7F16;&#x7801;">3.3 &#x80A1;&#x7968;&#x6DA8;&#x8DCC;&#x5E45;&#x5206;&#x7EC4;&#x6570;&#x636E;&#x53D8;&#x6210;one-hot&#x7F16;&#x7801;</h3>
<ul>
<li><strong>&#x4EC0;&#x4E48;&#x662F;one-hot&#x7F16;&#x7801;</strong></li>
</ul>
<p>&#x628A;&#x6BCF;&#x4E2A;&#x7C7B;&#x522B;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x5217;&#xFF0C;&#x8FD9;&#x4E9B;&#x5217;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x5217;&#x53EF;&#x4EE5;&#x4E3A;&#x8FD9;&#x4E2A;&#x6837;&#x672C;&#x53D6;&#x503C;&#x4E3A;1.&#x5176;&#x53C8;&#x88AB;&#x79F0;&#x4E3A;&#x70ED;&#x7F16;&#x7801;&#x3002;</p>
<p>&#x628A;&#x4E0B;&#x56FE;&#x4E2D;&#x5DE6;&#x8FB9;&#x7684;&#x8868;&#x683C;&#x8F6C;&#x5316;&#x4E3A;&#x4F7F;&#x7528;&#x53F3;&#x8FB9;&#x5F62;&#x5F0F;&#x8FDB;&#x884C;&#x8868;&#x793A;&#xFF1A;</p>
<p><img src="images/one_hot&#x7F16;&#x7801;.png" alt="image-20190316224151504"></p>
<ul>
<li><p>pandas.get_dummies(<em>data</em>, <em>prefix=None</em>)</p>
<ul>
<li><p>data:array-like, Series, or DataFrame</p>
</li>
<li><p>prefix:&#x5206;&#x7EC4;&#x540D;&#x5B57;</p>
</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5F97;&#x51FA;one-hot&#x7F16;&#x7801;&#x77E9;&#x9635;</span>
dummies = pd.get_dummies(p_counts, prefix=<span class="hljs-string">&quot;rise&quot;</span>)
</code></pre>
<p><img src="images/&#x54D1;&#x53D8;&#x91CF;&#x77E9;&#x9635;.png" alt="&#x54D1;&#x53D8;&#x91CF;&#x77E9;&#x9635;"></p>
<h2 id="4-&#x5C0F;&#x7ED3;">4 &#x5C0F;&#x7ED3;</h2>
<ul>
<li>&#x6570;&#x636E;&#x79BB;&#x6563;&#x5316;&#x3010;&#x77E5;&#x9053;&#x3011;<ul>
<li>&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x51CF;&#x5C11;&#x7ED9;&#x5B9A;&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x503C;&#x7684;&#x4E2A;&#x6570;</li>
<li>&#x5728;&#x8FDE;&#x7EED;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x57DF;&#x4E0A;&#xFF0C;&#x5C06;&#x503C;&#x57DF;&#x5212;&#x5206;&#x4E3A;&#x82E5;&#x5E72;&#x4E2A;&#x79BB;&#x6563;&#x7684;&#x533A;&#x95F4;&#xFF0C;&#x6700;&#x540E;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x7B26;&#x53F7;&#x6216;&#x6574;&#x6570;&#x503C;&#x4EE3;&#x8868;&#x843D;&#x5728;&#x6BCF;&#x4E2A;&#x5B50;&#x533A;&#x95F4;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x3002;</li>
</ul>
</li>
<li>qcut&#x3001;cut&#x5B9E;&#x73B0;&#x6570;&#x636E;&#x5206;&#x7EC4;&#x3010;&#x77E5;&#x9053;&#x3011;<ul>
<li>qcut:&#x5927;&#x81F4;&#x5206;&#x4E3A;&#x76F8;&#x540C;&#x7684;&#x51E0;&#x7EC4;</li>
<li>cut:&#x81EA;&#x5B9A;&#x4E49;&#x5206;&#x7EC4;&#x533A;&#x95F4;</li>
</ul>
</li>
<li>get_dummies&#x5B9E;&#x73B0;&#x54D1;&#x53D8;&#x91CF;&#x77E9;&#x9635;&#x3010;&#x77E5;&#x9053;&#x3011;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Pandas/section7.html" class="navigation navigation-prev " aria-label="Previous page: 高级处理-缺失值处理"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../Pandas/section9.html" class="navigation navigation-next " aria-label="Next page: 高级处理-合并"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"katex":{},"expandable-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
